<template>
  <div class="wrapper">
    <JForm :form-config="dynamicValidateForm" :read="read" @handleBoxEvent="handleBoxEvent" />
  </div>
</template>

<script>
import JForm from '@/components/JForm'
import { getDictListByType } from '@/api/dictionaries'

export default {
  name: 'AreaUpdate',
  components: { JForm },
  props: {
    emitData: {
      type: Object,
      default: () => ({})
    },
    read: {
      type: Boolean,
      default: false
    }
  },
  data() {
    const userInfo = [
      {
        name: 'functionName',
        label: '名称',
        type: 'string',
        required: false,
        placeholder: '名称'
      },
      {
        name: 'alias',
        label: '别名',
        type: 'string',
        required: false,
        placeholder: '别名'
      },
      {
        name: 'code',
        label: '编码',
        type: 'string',
        required: false
      },
      {
        name: 'isMenu',
        label: '是否菜单',
        type: 'option',
        required: false,
        value: 0,
        config: {
          // activeText: '是',
          // inactiveText: '否',
          // activeValue: '1',
          // inactiveValue: '0'
        }
      },
      {
        name: 'functionLevel',
        label: '菜单级别',
        type: 'string',
        required: false,
        placeholder: '菜单级别'
      },
      {
        name: 'icon',
        label: '图标',
        type: 'string',
        required: false,
        placeholder: '图标',
        config: {
          icon: true
        }
      },
      {
        name: 'url',
        label: '地址',
        type: 'string',
        required: false
      },
      // {
      //   name: 'parentId',
      //   label: '父级ID',
      //   type: 'string',
      //   required: false,
      //   placeholder: '领导人名字'
      // },
      {
        name: 'moudeSummary',
        label: '模块概述',
        type: 'string',
        required: false,
        placeholder: '模块概述'
      },
      {
        name: 'operateInstruction',
        label: '操作说明',
        type: 'string',
        required: false
      },
      {
        name: 'remark',
        label: '说明',
        type: 'string',
        required: false
      },
      {
        name: 'sort',
        label: '排序',
        type: 'string',
        required: false
      }
    ]
    return {
      // dynamicValidateForm: userInfo,
      userInfo,
      CITY_YN01: []

    }
  },
  computed: {
    dynamicValidateForm() {
      const data = this.userInfo
      const result = []
      data.forEach(i => {
        const { type, name } = i
        if (type === 'option') {
          i.config.options = this.filterOption(i)
        }
        i.value = this.emitData[name]
        result.push(i)
      })
      return result
    },
    isMenuOption() {
      const data = this.CITY_YN01
      data.forEach(item => {
        const { code, name } = item
        item.value = +code
        item.label = name
      })
      return data
    }
  },
  watch: {},
  created() {
    this.getDicCITY_TYPE()
  },
  mounted() {},
  methods: {
    getDicCITY_TYPE() {
      getDictListByType({ dictTypeCode: 'YN01' }).then(res => {
        const { code, data /* message */ } = res
        if (code === 200) { this.CITY_YN01 = data }
      })
    },
    handleBoxEvent(emitObj) {
      console.log(emitObj)
      this.submitForm(emitObj)
    },
    filterOption(item) {
      const key = item.name
      return this[`${key}Option`]
    },
    submitForm(emitObj) {
      this.$emit('handleBoxEvent', { target: emitObj })
    }
  }
}
</script>
<style lang="scss" scoped>
.wrapper{
   padding: 0px;
   margin: 0px;
}
</style>
